/*
    Watchpost - A file monitor program for the GNOME desktop
    Copyright (C) 2006 Andrew Resch

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <libgnomevfs/gnome-vfs.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gnome.h>

#include "interface.h"

void load_interface_files() {
	/* load the interface */
	char *glade_file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
				       "watchpost/watchpost.glade", TRUE, NULL);
	if (glade_file) {
		mainwindow_xml = glade_xml_new(glade_file, "main_window", NULL);
		status_icon_menu_xml = glade_xml_new(glade_file, "status_icon_popup_menu", NULL);
		about_xml = glade_xml_new(glade_file, "about_dialog", NULL);
		monitor_list_popup_xml = glade_xml_new(glade_file, "monitor_list_popup_menu", NULL);
		results_list_popup_xml = glade_xml_new(glade_file, "results_list_popup_menu", NULL);
		filechooser_xml = glade_xml_new(glade_file, "file_chooser_dialog", NULL);
	}
	else
	g_free(glade_file);
}

void setup_monitor_list_view() {
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;	
	/* setup the monitor list treeview */
	GtkTreeView *monitor_list_tree_view = (GtkTreeView *)glade_xml_get_widget(mainwindow_xml, "monitor_view");
	monitor_list_list_store = gtk_list_store_new(MONITOR_LIST_NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
	gtk_tree_view_set_model(monitor_list_tree_view, GTK_TREE_MODEL(monitor_list_list_store));
	gtk_tree_view_set_rules_hint(monitor_list_tree_view, TRUE);
	/* add filename column with an icon renderer */
	column = gtk_tree_view_column_new();
	gtk_tree_view_column_set_title(column, "Name");
	renderer = gtk_cell_renderer_pixbuf_new();
	gtk_tree_view_column_pack_start(column, renderer, FALSE);
	gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", MONITOR_LIST_COLUMN_ICON, NULL);
	renderer = gtk_cell_renderer_text_new();
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_set_attributes (column, renderer, "text", MONITOR_LIST_COLUMN_NAME, NULL);
	gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
	gtk_tree_view_column_set_resizable (column, TRUE);
	gtk_tree_view_column_set_sort_column_id (column, MONITOR_LIST_COLUMN_NAME);
	gtk_tree_view_column_set_reorderable (column, TRUE);
	gtk_tree_view_column_set_expand(column, TRUE);
	gtk_tree_view_append_column(monitor_list_tree_view, column);
}

void setup_results_list_view() {
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	/* setup the results list treeview */
	GtkTreeView *monitor_results_tree_view = GTK_TREE_VIEW(glade_xml_get_widget(mainwindow_xml, "results_view"));
	monitor_results_list_store = gtk_list_store_new(MONITOR_RESULTS_NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
	gtk_tree_view_set_model(monitor_results_tree_view, GTK_TREE_MODEL(monitor_results_list_store));
	gtk_tree_view_set_rules_hint(monitor_results_tree_view, TRUE);
	column = gtk_tree_view_column_new();
	gtk_tree_view_column_set_title(column, "Name");
	renderer = gtk_cell_renderer_pixbuf_new();
	gtk_tree_view_column_pack_start(column, renderer, FALSE);
	gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", MONITOR_RESULTS_COLUMN_ICON, NULL);
	renderer = gtk_cell_renderer_text_new();
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_set_attributes (column, renderer, "text", MONITOR_RESULTS_COLUMN_NAME, NULL);
	gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
	gtk_tree_view_column_set_resizable (column, TRUE);
	gtk_tree_view_column_set_sort_column_id (column, MONITOR_RESULTS_COLUMN_NAME);
	gtk_tree_view_column_set_reorderable (column, TRUE);
	gtk_tree_view_column_set_expand(column, TRUE);
	gtk_tree_view_append_column(monitor_results_tree_view, column);

	column = gtk_tree_view_column_new();
	gtk_tree_view_column_set_title(column, "Event");
	renderer = gtk_cell_renderer_pixbuf_new();
	gtk_tree_view_column_pack_start(column, renderer, FALSE);
	gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", MONITOR_RESULTS_COLUMN_EVENT_ICON, NULL);
	renderer = gtk_cell_renderer_text_new();
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_set_attributes (column, renderer, "text", MONITOR_RESULTS_COLUMN_EVENT, NULL);
	gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
	gtk_tree_view_column_set_resizable (column, TRUE);
	gtk_tree_view_column_set_sort_column_id (column, MONITOR_RESULTS_COLUMN_EVENT);
	gtk_tree_view_column_set_reorderable (column, TRUE);
	gtk_tree_view_column_set_expand(column, TRUE);
	gtk_tree_view_append_column(monitor_results_tree_view, column);

	renderer = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes("Time", renderer, "text", MONITOR_RESULTS_COLUMN_TIME, NULL);
	gtk_tree_view_column_set_sort_column_id(column, MONITOR_RESULTS_COLUMN_TIME);
	gtk_tree_view_append_column(monitor_results_tree_view, column);

}

void setup_status_icon() {
	/* set the system tray icon */
	status_icon = gtk_status_icon_new_from_icon_name("gnome-searchtool");
	gtk_status_icon_set_tooltip(status_icon, "File change monitor");
}
